package com.tledu.jsoup;

import com.tledu.httpclient.HttpUtils2;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

public class Jsoup02 {
    public static void main(String[] args) throws IOException {
        // 可以处理html字符串
        String xlHTML = HttpUtils2.get("https://www.sina.com.cn/", null);
        Document document = Jsoup.parse(xlHTML);
        Elements elements = document.getElementsByClass("list-a news_top");
        for (Element el : elements) {
            System.out.println(el.html());
            // 拿到子集之后
            Elements aElements = el.getElementsByTag("a");
            // 根据eq的api可以获取对应元素, innerText
             System.out.println(aElements.eq(0).text());
             // 获取对应的属性
             System.out.println(aElements.eq(0).attr("href"));
        }
    }
}
